﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows.Data;

namespace ComicReader.Helpers
{
    public class GetFileSystemInformationConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (value is DriveInfo)
                {
                    var driveInfo = new DirectoryInfo((value as DriveInfo).RootDirectory.Name);
                    return driveInfo.GetDirectories();
                }

                if (value is DirectoryInfo)
                {
                    var directoryContent = new List<FileSystemInfo>();
                    directoryContent.AddRange((value as DirectoryInfo).GetDirectories());
                    directoryContent.AddRange((value as DirectoryInfo).GetFiles("*.cbr"));
                    directoryContent.AddRange((value as DirectoryInfo).GetFiles("*.cbz"));
                    return directoryContent;
                }
            }
            catch (Exception)
            {

            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
